package com.draby.starfantasymaze.factories.map;

import com.draby.starfantasymaze.dto.map.Map;
import com.draby.starfantasymaze.dto.map.RectangleMap;
import com.draby.starfantasymaze.enums.Mode;

import java.util.Random;

public class RectangleMapFactory implements IMapFactory {

    private final int easyHeight = 12;
    private final int easyWidth = 8;
    private final int normalHeight = 20;
    private final int normalWidth = 12;
    private final int hardHeight = 32;
    private final int hardWidth = 20;

    /**
     * 根据模式创建矩形地图
     * @param mode 游戏模式
     * @return 创建好的地图
     */
    @Override
    public Map createMap(Mode mode) {
        Map map = new RectangleMap();
        switch (mode) {
            case EASY:
                // 简单模式
                map.initMap(easyHeight, easyWidth);
                break;
            case NORMAL:
                // 普通模式
                map.initMap(normalHeight, normalWidth);
                break;
            case HARD:
                // 困难模式
                map.initMap(hardHeight, hardWidth);
                break;
            case CUSTOMIZE:
                // 自定义地图大小，后置(到 activity 中)初始化地图
                break;
            case RANDOM:
                // 随机地图大小
                Random r = new Random();
                int height = r.nextInt(hardHeight - easyHeight + 1) + easyHeight;
                int width = r.nextInt(hardWidth - easyWidth + 1) + easyWidth;
                map.initMap(height, width);
                break;
            default:
                map = null;
        }
        return map;
    }
}
